home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AE Sample (TC5) / Interaction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-01  |  2.5 KB  |  90 lines  |  [TEXT/KAHL]

  1. /* Interaction.c */
  2.  
  3. /* This file demonstrates the techniques necesary for interacting with the user */
  4. /* when you receive an Apple event.                                             */
  5.  
  6. #include    "AESimple.h"
  7.  
  8. pascal Boolean    MyIdleProc(EventRecord *theEvent, long *sleep, RgnHandle *mouseRgn);
  9.  
  10. OSErr MyInteractWithUser(Boolean isUrgent)
  11. {
  12.     NMRec        notice;
  13.     Handle        mySmallIcon;
  14.     Handle        notificationString;
  15.     SignedByte    sicnState, strState;
  16.     OSErr        err;
  17.     
  18.     /* Set up a notification which blinks a small icon and (optionally) */
  19.     /* shows a dialog to the user. */
  20.     mySmallIcon = Get1Resource('SICN', 128);
  21.     sicnState = HGetState(mySmallIcon);
  22.     HNoPurge(mySmallIcon);
  23.     notificationString = (Handle)GetString(3001);
  24.     strState = HGetState(notificationString);
  25.     MoveHHi(notificationString);
  26.     HLock(notificationString);
  27.     
  28.     notice.qType = nmType;
  29.     notice.nmMark = 1;
  30.     notice.nmIcon = mySmallIcon;
  31.     notice.nmSound = 0L;
  32.     if (isUrgent) 
  33.         notice.nmStr = (StringPtr)*notificationString;
  34.     else
  35.         notice.nmStr = 0L;
  36.     notice.nmResp = 0L;
  37.     notice.nmRefCon = 0L;
  38.     
  39.     /* If we're in the background, the next call will either switch us to the front, */
  40.     /* call the Notification Manager, or return an error indicating that user interaction */
  41.     /* is not allowed. */
  42.     /* If interaction is allowed (and we're in the back), this call will wait for our */
  43.     /* application to become frontmost and then return noErr. */
  44.     /* If we're already in front, it returns noErr. */
  45.     err = AEInteractWithUser(kAEDefaultTimeout, (NMRecPtr)¬ice, (IdleProcPtr)MyIdleProc);
  46.     HSetState(mySmallIcon, sicnState);
  47.     HSetState(notificationString, strState);
  48.     return err;
  49. } /* MyInteractWithUser */
  50.  
  51.  
  52. /* The following code is taken from CShell, by Keith Rollin and Eric Soldan of Mac DTS. */
  53. /* (Yes, I have permission to copy it.) */
  54.  
  55. /* MyIdleProc
  56. **
  57. ** This routine gets either an updateEvt, an activateEvt, a nullEvent or an
  58. ** OSEvent.  The first time called it will get a nullEvent; this is its chance
  59. ** to set the sleep value and mouseRegion that will be passed to WaitNextEvent
  60. ** by the caller within the AEM.  After that it will also get events of the
  61. ** other types (which are lost if masked out by the AEM) and must do with them
  62. ** whatever is appropriate.
  63. */
  64.  
  65. pascal Boolean    MyIdleProc(EventRecord *theEvent, long *sleep, RgnHandle *mouseRgn)
  66. {
  67.     switch (theEvent->what) {
  68.  
  69.         case updateEvt:
  70.             DoUpdate((WindowPtr)theEvent->message);
  71.         break;
  72.         
  73.         case activateEvt:
  74.             DoActivate(theEvent);
  75.         break;
  76.             
  77.         case app4Evt:
  78.         break;
  79.  
  80.         case nullEvent:
  81.             *mouseRgn = NIL;
  82.             *sleep    = 600L;    /* 10 seconds */
  83.             break;
  84.     }
  85.     return(false);
  86. }
  87.  
  88.  
  89.  
  90.